package com.ktg.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ktg.ktgcommon.domain.mainData.MdClient;
import com.ktg.ktgcommon.filter.TokenVerifyFilter;
import com.ktg.ktgcommon.query.QueryClient;
import com.ktg.mapper.ClientMapper;
import com.ktg.service.ClientService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class ClientServiceImpl implements ClientService {

    @Autowired
    private ClientMapper clientMapper;
    @Override
    public Page<MdClient> selectPage(Page<MdClient> page, QueryClient queryClient) {
        Page<MdClient> mdClientPage = clientMapper.selectPage(page, queryClient);
        return mdClientPage;
    }

    @Override
    public MdClient checkClientById(Integer clientId) {
        MdClient mdClient = clientMapper.checkClientById(clientId);
        return mdClient;
    }

    @Override
    public Integer AddOrChClient(MdClient mdClient) {
        //解析jwt获取user信息
        TokenVerifyFilter tokenVerifyFilter=new TokenVerifyFilter();
        if (mdClient.getClientId()!=null) {
            //设置更新时间
            mdClient.setUpdateTime(new Date());
            //设置更新者名称
            mdClient.setUpdateBy(tokenVerifyFilter.getUserName().getUsername());
            return clientMapper.changeMdClient(mdClient);
        }else {
            //设置创建时间
            mdClient.setCreateTime(new Date());
            //设置创建者名称
            mdClient.setCreateBy(tokenVerifyFilter.getUserName().getUsername());
            return clientMapper.addMdClient(mdClient);
        }
    }

    @Override
    public Integer delClient(Integer clientId) {
        Integer integer = clientMapper.delClient(clientId);
        return integer;
    }

    @Override
    public Integer delClientIdArray(List<Integer> arrayClientId) {
        Integer integer = clientMapper.delClientIdArray(arrayClientId);
        return integer;
    }
}
